//
//  LGStatusLIstViewModel.m
//  微博oc版
//
//  Created by Apple_Lzzy27 on 16/10/13.
//  Copyright © 2016年 Apple_Lzzy27. All rights reserved.
//

#import "LGStatusLIstViewModel.h"
@interface LGStatusLIstViewModel()
@property (nonatomic, strong) LGStatusListModel *model;
@end


@implementation LGStatusLIstViewModel

- (NSMutableArray *)statusListArray{
    if (_statusListArray == nil) {
        _statusListArray = [NSMutableArray array];
    }
    
    return _statusListArray;
}

/**
 *  获取微博数据
 */
- (void)status:(BOOL)isFull completion:(void(^)(BOOL isSuccess))completion{
    
    LGStatusListModel *fistObj = self.statusListArray.firstObject;
    LGStatusListModel *lastObj = self.statusListArray.lastObject;
    //判断是否是上拉刷新
    NSUInteger sinc = isFull ? 0 : fistObj.id;
     NSUInteger max = !isFull ? 0 : lastObj.id;
    
    
    [[LGNetWorkingManager shard] statusList:max since_id:sinc completion:^(BOOL isSuccess, NSArray *array) {
        
        //包字典赋值给模型
     NSArray  *statusArray = [NSArray yy_modelArrayWithClass:[LGStatusListModel class] json:array];
        
        NSLog(@"刷新了%zd条消息",statusArray.count);
        if (!isFull) {
            NSRange range = NSMakeRange(0, statusArray.count);
            NSIndexSet *index =[NSIndexSet indexSetWithIndexesInRange:range];
            [self.statusListArray insertObjects:statusArray atIndexes:index];
        }else{
            [self.statusListArray addObjectsFromArray:statusArray];
            
        }
       
        
        completion(isSuccess);
    }];
    
}



@end


